#/*************************************************************************
#    > File Name: examples/example_list.py
#    > Author: Yan Wang
#    > Mail: wangyan@imnu.edu.cn
#    > Created Time: 2022年06月22日 星期三 18时38分06秒
# ************************************************************************/
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.path.append('../Lib/')
from Load_Lib import * 

print("The examples in this file are:")
ex_name={"1":"Get_Maplist_Key"
,"2":"Judge_Element_Exist"
,"3":"Get_Dict_from_Dataframe"
,"4":"Split_list_n_list"
,"5":"Load_THDM_Param"
,"6":"Make_Dictlist_from_DF"
,"7":"Trans_Value_to_Dict"
,"8":"Trans_MultiValue_to_Dict"
,"9":"Trans_ValueDict_to_Dict"
,"10":"Trans_Dict_to_list"
,"11":"Remove_Nested_List"
,"all":"all examples"}     #字典，所有对应函数为Lib/List_Operation.py
for key in ex_name:
	print(key, ex_name[key])    #if条件语句，如果key在ex_name里面，则输出eg：1 Get_Maplist_Key  
num=input("请输入想要运行的例子：")



if num == "1" or num == ex_name["1"] or num == "all":
# Get_Maplist_Key
# 一个参数A为输入的列表
# 查找列表中所有的key名称
# 最后输出为：['process', 'tmp', 'file']
	input_path_dict={"process":"{}",
					"tmp" :"{}",
					"file":"{}"}
	Exhibit_Function(Get_Maplist_Key, [input_path_dict])


if num == "2" or num == ex_name["2"] or num == "all":
# Judge_Element_Ex==t
# 两个参数(A,B),A为输入的列表,B为列表内的元素
# 判断input_list中6是否存在
# 最后返回为False
	input_list=[1,2,3,4,5]
	Exhibit_Function(Judge_Element_Exist, [input_list, 6])


if num == "3" or num == ex_name["3"] or num == "all":
# Get_Dict_from_Dataframe
# 两个元素(A,B),A为被读取的数据文件,B为需要的数据
# 读取df_name并从中提取dict_name,且将其转换为科学表达式的列表
# 最后输出为df_name并且冲中提取了"mh","mch"两列数据(列表)
	df_name="examples/test_input/data_grid_mh_mch.tsv"
	df = pd.read_table(df_name)
	dict_name=["mh","mch"]
	Exhibit_Function(Get_Dict_from_Dataframe, [df,dict_name])


if num == "4" or num == ex_name["4"] or num == "all":
# Split_List_n_List 
# 两个元素(A,B),A为输入的列表,B为要将列表分成的个数
# 将input_list列表分为num个列表
# 最后输出为：[[1, 2, 3], [4, 5, 6], [7, 8]]
	input_list=[1,2,3,4,5,6,7,8]
	num=3
	Exhibit_Function(Split_List_n_List, [input_list,num])


if num == "5" or num == ex_name["5"] or num == "all":
# Load_THDM_Param 
# 两个参数(A,B),A为被读取的数据文件,B为需要的数据
# 打开df_name,只读取dict_name
# 最后输出为"mh","mch"两列数据(列表)
	df_name="examples/test_input/data_grid_mh_mch.tsv"
	dict_name=["mh","mch"]
	Exhibit_Function(Load_THDM_Param, [df_name,dict_name])


if num == "6" or num == ex_name["6"] or num == "all":
# Make_Dictlist_from_DF
# 四个参数(A,B,C,df_num=0),A为读取的数据文件,B为要将所读取的数据分成的组数,C为所读取的数据列表,df_num=0为默认值
# 读取df_name中的input_value_list,并且将其分为node_num(每组数据要各自分组),最后输出为一个dict,其内包含已被分组的input_value_list
# 最后输出为：
# {'tb': ['[20.663656, 10.436171, 8.207647999999999, 17.589038000000002, 9.616626]',
#  '[9.223365, 7.920896000000001, 13.431135000000001, 10.512284, 19.236976000000002]',
#  '[13.817010999999999, 18.254585000000002, 18.61391, 12.648762]'],
#  'sba': ['[-0.052204999999999994, -0.10005, -0.123984, -0.058461, -0.106299]',
#  '[-0.11103699999999998, -0.128448, -0.078794, -0.09768500000000001, -0.054036]',
#  '[-0.07492599999999999, -0.057912, -0.058675, -0.08508099999999999]']}
	node_num=3
	df_name="examples/test_input/data_grid_mh_mch.tsv"
	df = pd.read_table(df_name)
	input_value_list=["tb", "sba"]
	Exhibit_Function(Make_Dictlist_from_DF,[df, node_num, input_value_list])


if num == "7" or num == ex_name["7"] or num == "all":
# Trans_Value_to_Dict
# 两个参数(A,B),A为一个字典,B为需要传入字典内的字符
# 将value传入dict_name中的{value}位置上
# 最后输出为：{'1': 'test1_aaa', '2': 'test2_aaa'}
	dict_name={"1":"test1_{}", "2":"test2_{}"}
	value="aaa"
	Exhibit_Function(Trans_Value_to_Dict,[dict_name,value])


if num == "8" or num == ex_name["8"] or num == "all":
# Trans_MultiValue_to_Dict
# 两个参数(A,B),A为一个字典,B为需要传入字典内的字符
# 与以上函数不同的是，要将标识符$后面的内容做替换
# 最后输出为：{'1': 'test1_aaa', '2': 'test2_bbb'}
	dict_name={"1":"test1_$f1", "2":"test2_$f2"}
	value={"f1":"aaa","f2":"bbb"}
	Exhibit_Function(Trans_MultiValue_to_Dict,[dict_name,value])
	#print(Trans_MultiValue_to_Dict(dict_name,value))


if num == "9" or num == ex_name["9"] or num == "all":
# Trans_ValueDict_to_Dict
# 同上述两函数
# 最后输出为：{'1': 'test1_aaa', '2': 'test2_bbb'}
	dict_name={"1":"test1_{}", "2":"test2_{}"}
	value={"1":"aaa","2":"bbb"}
	xhibit_Function(Trans_ValueDict_to_Dict,[dict_name,value])


if num == "10" or num == ex_name["10"] or num == "all":
# Trans_Dict_to_list
# 一个参数---一个字典
# 将同类型value的dict，转换为list
# 最后输出为： ['test1_{}', 'test2_{}']
	dict_name={"1":"test1_{}", "2":"test2_{}"}
	Exhibit_Function(Trans_Dict_to_list,[dict_name])


if num == "11" or num == ex_name["11"] or num == "all":
# Remove_Nested_List(listt)
# 去除空列表
# 输出为：[[1, 2, 3, 0], [4, 5, 7]]
	list_name=[[1, 2, 3, 0, []], [], [], [], [4, 5, [], 7]]
	Exhibit_Function(Remove_Nested_List,[list_name])

